﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;

namespace Presentation
{
    public partial class UserControlTheoCongTy : UserControl
    {
        public UserControlTheoCongTy()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void btnTracuu_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime tngay = DateTime.Parse(dtpTungay.Text);
                DateTime dngay = DateTime.Parse(dtpDenngay.Text);
                CongTyNhapHangDao ctnhDao = new CongTyNhapHangDao();
                CongTyNhapHangDto[] ctnhDto = ctnhDao.SelectCongtynhaphang(tngay, dngay);

                dgvTheocongty.AutoGenerateColumns = false;
                dgvTheocongty.DataSource = ctnhDto;
                float sum = 0;
                for (int i = 0; i < dgvTheocongty.Rows.Count; i++)
                {
                    sum = sum + float.Parse(dgvTheocongty.Rows[i].Cells[3].Value.ToString());
                }
                txtTongtien.Text = Convert.ToDecimal(sum).ToString();
            }
            catch (Exception)
            {

                MessageBox.Show("Không có dữ liệu!");
            }
        }

        private void dgvTheocongty_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt"); ;
        }

        private void btnLuuBaoCao_Click(object sender, EventArgs e)
        {
            Utils.ExportToExcel(dgvTheocongty);
        }
    }
}
